<?php
// +----------------------------------------------------------------------
// | @filename UpdateRoleRequest.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-29 17:39:37
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Requests\Role;

use Addons\Backend\Http\Requests\BaseRequest;

class UpdateRoleRequest extends BaseRequest
{
    public function rules(): array
    {
        $id = $this->request->get('id');
        return [
            'id' => ['bail', 'required', 'exists:roles,id'],
            'name' => ['bail', 'required', 'min:2', 'max:255', "unique:roles,name,$id"]
        ];
    }

    public function messages(): array
    {
        return [
            'id.exists' => '角色不存在',
            'name.required' => '请输入角色名',
            'name.unique' => '角色名已存在',
            'name.min' => '角色名不能少于2位',
            'name.max' => '角色名不能大于255位'
        ];
    }

    public function authorize(): bool
    {
        return true;
    }
}
